package com.gy.hsim.bservice.message.restful;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gy.hsim.bservice.framework.bean.QueryVerifyReponse;
import com.gy.hsim.bservice.framework.enums.MessageResultEnum;
import com.gy.hsim.bservice.framework.mapper.MessageMapper;
import com.gy.hsim.bservice.framework.restful.BaseController;
import com.gy.hsim.bservice.friendInfo.bean.QueryFriendReq;
import com.gy.hsim.bservice.message.bean.Message;
import com.gy.hsim.bservice.message.bean.MessageSetting;
import com.gy.hsim.bservice.message.service.MessageService;
import com.gy.hsxt.uc.search.api.IUCUserInfoSearchService;
import com.gy.hsxt.uc.search.bean.SearchUserInfo;

/**
 * 
 * @ClassName: MessageController 
 * @Description: 查询消息Controller 
 * @author quanrj 
 * @date 2015-11-10 上午09:37:19
 */
@Controller
@RequestMapping("/message")
public class MessageController extends BaseController {
	private static final Logger log = LoggerFactory
			.getLogger(Message.class);
	
	@Autowired
	private MessageService messageService;
	
	@Autowired
	private IUCUserInfoSearchService userInfoSearchService;
	
	/**
	 * 查询历史信息请求URL: http://localhost:8099/hsim-bservice/message/queryMessageRecordList
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryMessageRecordList",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryMessageRecordList(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		QueryVerifyReponse resp = new QueryVerifyReponse();
		List<Message> MessageList = new ArrayList<Message>();
		try {
			//获取前端传过来的查询参数			
			JSONObject object = (JSONObject)request.getAttribute("object");
			Message message = JSON.toJavaObject(object, Message.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//message = returnMessageInfoByParam(request);
			
			
			//校验必填项fromUid,toUid
			if(message.getFromUid() == null || message.getFromUid().equals("") || message.getToUid() == null || message.getToUid().equals("")){
				resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
				resp.setMessage("发送者:fromUid和接收者:toUid都不能为空！");
				resp.setVerifyFlag("0");
				return resp;
			}
			
			//计算开始和结束索引
			if( message.getPageNum() > 0 && message.getPageSize() > 0){
				int pageNum = message.getPageNum();
				int pageSize = message.getPageSize();
				message.setStartIndex((pageNum-1)*pageSize);
				message.setEndIndex(pageSize);
			}
			
			//得到数据返回前端
			MessageList = messageService.queryMessageRecordList(message);                //分页情况下的消息列表
			//遍历查询出来的数据，如果发送方是消费者并且接收方是企业或者企业操作员，把接收方换成企业客户号
			for(Message messageData : MessageList){
				if(messageData.getFromUid().indexOf("c") > 0 && messageData.getToUid().indexOf("e") > 0){
					String custIdData = messageData.getToUid();
					String [] custIdArr = custIdData.split("_");
					String custId = custIdArr[2];
					if(custId.length() > 11){
						SearchUserInfo SearchUserInfo = userInfoSearchService.getById(custId);
						if(SearchUserInfo != null){
							messageData.setToUid(SearchUserInfo.getEntCustId());
						}						
					}
				}
			}
			int messageTotalRows = messageService.queryMessageRecordListCount(message);  //不分页的情况下的消息总数
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			resp.setTotalRows(messageTotalRows);
			resp.setRows(MessageList);
			System.out.println("【返回的记录总数】：" + messageTotalRows);
			log.debug("【返回的记录总数】：" + messageTotalRows);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
			resp.setTotalRows(0);
			resp.setVerifyFlag("0");
		}
       return resp;
	}
	
	/**
	 * 查询总历史信息请求URL: http://localhost:8099/hsim-bservice/message/queryMessageRecordTotalList
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryMessageRecordTotalList",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryMessageRecordTotalList(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		QueryVerifyReponse resp = new QueryVerifyReponse();		
		List<Message> MessageList = new ArrayList<Message>();
		try {
			//获取前端传过来的查询参数
			JSONObject object = (JSONObject)request.getAttribute("object");
			Message message = JSON.toJavaObject(object, Message.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//当传过来的dialogueFlag值为Y(即查询对话信息的时候)的时候校验必填项fromUid,toUid
			if(message.getDialogueFlag().equals("Y")){
				if(message.getFromUid() == null || message.getFromUid().equals("") || message.getToUid() == null || message.getToUid().equals("")){
					resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
					resp.setMessage("发送者:fromUid和接收者:toUid都不能为空！");
					resp.setVerifyFlag("0");
					return resp;
				}
			}
						
			//计算开始和结束索引
			if( message.getPageNum() > 0 && message.getPageSize() > 0){
				int pageNum = message.getPageNum();
				int pageSize = message.getPageSize();
				message.setStartIndex((pageNum-1)*pageSize);
				message.setEndIndex(pageSize);
			}
			
			//得到数据返回前端
			MessageList = messageService.queryMessageRecordTotalList(message);                //分页情况下的消息列表
			//遍历查询出来的数据，如果发送方是消费者并且接收方是企业或者企业操作员，把接收方换成企业客户号
			for(Message messageData : MessageList){
				if(messageData.getFromUid().indexOf("c") > 0 && messageData.getToUid().indexOf("e") > 0){
					String custIdData = messageData.getToUid();
					String [] custIdArr = custIdData.split("_");
					String custId = custIdArr[2];
					if(custId.length() > 11){
						SearchUserInfo SearchUserInfo = userInfoSearchService.getById(custId);
						if(SearchUserInfo != null){
							messageData.setToUid(SearchUserInfo.getEntCustId());
						}						
					}
				}
			}
			int messageTotalRows = messageService.queryMessageRecordTotalListCount(message);  //不分页的情况下的消息总数
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			resp.setTotalRows(messageTotalRows);
			resp.setRows(MessageList);
			System.out.println("【返回的记录总数】：" + messageTotalRows);
			log.debug("【返回的记录总数】：" + messageTotalRows);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
			resp.setTotalRows(0);
			resp.setVerifyFlag("0");
		}
       return resp;
	}
	
	/**
	 * 查询推送消息历史信息请求URL: http://localhost:8099/hsim-bservice/message/queryPushMessageRecordList
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryPushMessageRecordList",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryPushMessageRecordList(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		QueryVerifyReponse resp = new QueryVerifyReponse();		
		List<Message> MessageList = new ArrayList<Message>();
		try {
			//获取前端传过来的查询参数
            JSONObject object = (JSONObject)request.getAttribute("object");
			Message message = JSON.toJavaObject(object, Message.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//校验必填项toUid
			if(message.getToUid() == null || message.getToUid().equals("")){
				resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
				resp.setMessage("接收者:toUid不能为空！");
				resp.setVerifyFlag("0");
				return resp;
			}
			
			//计算开始和结束索引
			if( message.getPageNum() > 0 && message.getPageSize() > 0){
				int pageNum = message.getPageNum();
				int pageSize = message.getPageSize();
				message.setStartIndex((pageNum-1)*pageSize);
				message.setEndIndex(pageSize);
			}
			
			//得到数据返回前端
			MessageList = messageService.queryPushMessageRecordList(message);                //分页情况下的消息列表
			int messageTotalRows = messageService.queryPushMessageRecordListCount(message);  //不分页的情况下的消息总数
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			resp.setTotalRows(messageTotalRows);
			resp.setRows(MessageList);
			System.out.println("【返回的记录总数】：" + messageTotalRows);
			log.debug("【返回的记录总数】：" + messageTotalRows);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
			resp.setTotalRows(0);
			resp.setVerifyFlag("0");
		}
       return resp;
	}
	
	/**
	 * 查询推送总历史信息请求URL: http://localhost:8099/hsim-bservice/message/queryPushMessageRecordTotalList
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryPushMessageRecordTotalList",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryPushMessageRecordTotalList(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();		
		List<Message> MessageList = new ArrayList<Message>();
		try {
			//获取前端传过来的查询参数
			JSONObject object = (JSONObject)request.getAttribute("object");
			Message message = JSON.toJavaObject(object, Message.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
									
			//计算开始和结束索引
			if( message.getPageNum() > 0 && message.getPageSize() > 0){
				int pageNum = message.getPageNum();
				int pageSize = message.getPageSize();
				message.setStartIndex((pageNum-1)*pageSize);
				message.setEndIndex(pageSize);
			}
			
			//得到数据返回前端
			MessageList = messageService.queryPushMessageRecordTotalList(message);                //分页情况下的消息列表
			int messageTotalRows = messageService.queryPushMessageRecordTotalListCount(message);  //不分页的情况下的消息总数
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			resp.setTotalRows(messageTotalRows);
			resp.setRows(MessageList);
			System.out.println("【返回的记录总数】：" + messageTotalRows);
			log.debug("【返回的记录总数】：" + messageTotalRows);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
			resp.setTotalRows(0);
			resp.setVerifyFlag("0");
		}
       return resp;
	}
	
	/**
	 * 消息系统设置: http://localhost:8099/hsim-bservice/message/messageSetting
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/messageSetting",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse messageSetting(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();		
		try {
			//获取前端传过来的查询参数
			JSONObject object = (JSONObject)request.getAttribute("object");
			MessageSetting messageSetting = JSON.toJavaObject(object, MessageSetting.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
									
			/*InputStream is = null;
			is = request.getInputStream();
			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);
			MessageSetting messageSetting = JSON.toJavaObject(JSON.parseObject(jsonStr), MessageSetting.class);*/
						
			//消息设置
			messageService.messageSetting(messageSetting);			
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());			
		}
       return resp;
	}
	
	/**
	 * 用户查询消息设置: http://localhost:8099/hsim-bservice/message/queryMessageSetting
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryMessageSetting",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryMessageSetting(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();		
		try {
			//获取前端传过来的查询参数
			JSONObject object = (JSONObject)request.getAttribute("object");
			MessageSetting messageSetting = JSON.toJavaObject(object, MessageSetting.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
									
			/*InputStream is = null;
			is = request.getInputStream();
			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码） 
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);
			MessageSetting messageSetting = JSON.toJavaObject(JSON.parseObject(jsonStr), MessageSetting.class);*/
						
			//查询消息设置
			List<MessageSetting> messageSettingList = new ArrayList<MessageSetting>();
			messageSettingList = messageService.queryMessageSettingList(messageSetting);
			int totalRows = messageSettingList.size();
			resp.setRows(messageSettingList);
			resp.setTotalRows(totalRows);
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
			resp.setTotalRows(0);
		}
       return resp;
	}
	
	/**	
	 * @return 通过前端传过来的信息转换成message对象
	 * @throws IOException 
	 * @throws Exception 
	 */
	/*public Message returnMessageInfoByParam(HttpServletRequest request) throws IOException{
		InputStream is = null;
		is = request.getInputStream();
		
		byte bytes[] = new byte[request.getContentLength()];
		is.read(bytes);
		//得到请求中的内容区数据（以CharacterEncoding解码）
		String jsonStr = new String(bytes, "utf-8");
		System.out.println("【接收到的json】：" + jsonStr);
		log.debug("【接收到的json】：" + jsonStr);
		Message message = JSON.toJavaObject(JSON.parseObject(jsonStr), Message.class);
		return message;
	}*/
	
	/**
	 * 用户查询群消息设置: http://localhost:8099/hsim-bservice/message/queryGroupMessage
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryGroupMessage",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryGroupMessage(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();		
		List<Message> MessageList = new ArrayList<Message>();
		try {
			//获取前端传过来的查询参数
			JSONObject object = (JSONObject)request.getAttribute("object");
			Message message = JSON.toJavaObject(object, Message.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			/*InputStream is = null;
			is = request.getInputStream();
			
			byte bytes[] = new byte[request.getContentLength()];
			is.read(bytes);
			//得到请求中的内容区数据（以CharacterEncoding解码）
			String jsonStr = new String(bytes, "utf-8");
			System.out.println("【接收到的json】：" + jsonStr);
			log.debug("【接收到的json】：" + jsonStr);
			Message message = JSON.toJavaObject(JSON.parseObject(jsonStr), Message.class);*/
			
			//计算开始和结束索引
			if( message.getPageNum() > 0 && message.getPageSize() > 0){
				int pageNum = message.getPageNum();
				int pageSize = message.getPageSize();
				message.setStartIndex((pageNum-1)*pageSize);
				message.setEndIndex(pageSize);
			}
			
			//得到数据返回前端
			MessageList = messageService.queryGroupMessageList(message);                //分页情况下的消息列表
			int messageTotalRows = messageService.queryGroupMessageListCount(message);  //不分页的情况下的消息总数
			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
			resp.setTotalRows(messageTotalRows);
			resp.setRows(MessageList);
			System.out.println("【返回的记录总数】：" + messageTotalRows);
			log.debug("【返回的记录总数】：" + messageTotalRows);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
			resp.setTotalRows(0);
			resp.setVerifyFlag("0");
		}
       return resp;
	}
	
	/**
	 * 即时消息返回最近联系人 返回URL: http://localhost:8099/hsim-bservice/message/queryRecentContactsMsgList
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 * @throws Exception 
	 */
	@RequestMapping(value = "/queryRecentContactsMsgList",method = RequestMethod.POST)
	public  @ResponseBody QueryVerifyReponse queryRecentContactsMsgList(HttpServletRequest request,
			HttpServletResponse response) throws IOException{
		
		QueryVerifyReponse resp = new QueryVerifyReponse();		
		List<Message> messageList = new ArrayList<Message>();
		try {
			//获取前端传过来的查询参数
			JSONObject object = (JSONObject)request.getAttribute("object");
			Message message = JSON.toJavaObject(object, Message.class);
			System.out.println("【接收到的json】：" + object);
			log.debug("【接收到的json】：" + object);
			
			//计算开始和结束索引
			if( message.getPageNum() > 0 && message.getPageSize() > 0){
				int pageNum = message.getPageNum();
				int pageSize = message.getPageSize();				
				message.setStartIndex((pageNum-1)*pageSize);
				message.setEndIndex(pageSize);
			}
			
			//判断是企业操作员还是消费者查询消息
			String ifOperator = message.getIfOperator();
			if(ifOperator.equals("N")){  //消费者查询最近联系人消息
				message.setToUid(message.getToUid().substring(0,11));
				messageList = messageService.queryConsumerRecentContactsMsgList(message);
				//遍历查询出来的数据，如果发送方是消费者并且接收方是企业或者企业操作员，把接收方换成企业客户号
				for(Message messageData : messageList){
					if(messageData.getFromUid().indexOf("c") > 0 && messageData.getToUid().indexOf("e") > 0){
						String custIdData = messageData.getToUid();
						String [] custIdArr = custIdData.split("_");
						String custId = custIdArr[2];
						if(custId.length() > 11){
							SearchUserInfo SearchUserInfo = userInfoSearchService.getById(custId);
							if(SearchUserInfo != null){
								messageData.setToUid(SearchUserInfo.getEntCustId());
							}						
						}
					}
				}
				int messageTotalRows = messageService.queryConsumerRecentContactsMsgListCount(message);
				resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
				resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
				resp.setTotalRows(messageTotalRows);
				resp.setRows(messageList);
				System.out.println("【返回的记录总数】：" + messageTotalRows);
				log.debug("【返回的记录总数】：" + messageTotalRows);
			} else {   //企业操作员查询最近联系人消息
				messageList = messageService.queryOperRecentContactsMsgList(message);
				//给发送方和接收方设置昵称
				for(Message messageData : messageList){										
					String fromUidData = messageData.getFromUid();
					String [] fromUidDataArr = fromUidData.split("_");
					String fromCustId = fromUidDataArr[2];					
					String toUidData = messageData.getToUid();
					String [] toUidDataArr = toUidData.split("_");
					String toCustId = toUidDataArr[2];
					
					String senderNickName = "";
					String receiverNickName = "";
					
					if(fromCustId!=null && !fromCustId.equals("")){   //给发送方设置用户昵称
						if(fromCustId.length() > 11){
							SearchUserInfo SearchUserInfo = userInfoSearchService.getById(fromCustId);
							if(SearchUserInfo != null){
								if(fromUidData.indexOf("e") > 0){
									senderNickName = (SearchUserInfo.getOperName() == null || SearchUserInfo.getOperName().equals(""))?SearchUserInfo.getCustId():SearchUserInfo.getOperName();
								} else {
									senderNickName = (SearchUserInfo.getNickName() == null || SearchUserInfo.getNickName().equals(""))?SearchUserInfo.getCustId():SearchUserInfo.getNickName();
								}
								
							}							 
						}
						messageData.setSenderNickName(senderNickName);
					}
					
					if(toCustId!=null && !toCustId.equals("")){   //给接收方设置用户昵称
						if(toCustId.length() > 11){
							SearchUserInfo SearchUserInfo = userInfoSearchService.getById(toCustId);
							if(SearchUserInfo != null){
								if(toUidData.indexOf("e") > 0){
									receiverNickName = (SearchUserInfo.getOperName() == null || SearchUserInfo.getOperName().equals(""))?SearchUserInfo.getCustId():SearchUserInfo.getOperName();
								} else {
									receiverNickName = (SearchUserInfo.getNickName() == null || SearchUserInfo.getNickName().equals(""))?SearchUserInfo.getCustId():SearchUserInfo.getNickName();
								}
								
							}						 
						}
						messageData.setReceiverNickName(receiverNickName);
					}
					
				}
				int messageTotalRows = messageService.queryOperRecentContactsMsgListCount(message);
				resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());
				resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());
				resp.setTotalRows(messageTotalRows);
				resp.setRows(messageList);
				System.out.println("【返回的记录总数】：" + messageTotalRows);
				log.debug("【返回的记录总数】：" + messageTotalRows);
			}			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.toString());
			e.printStackTrace();
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());
			resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
			resp.setTotalRows(0);
			resp.setVerifyFlag("0");
		}
       return resp;
	}
}
